﻿using System;
using TrueSync;

namespace HEFramework
{
    public static class TransformComponentSystem
    {
        [EntitySystem]
        public class TransformComponentAwakeSystem : AwakeSystem<TransformComponent>
        {
            protected override void Awake(TransformComponent _self)
            {
                _self.P = TSVector.zero;
            }
        }

        public static TSVector GetTopPos(this TransformComponent _self, AttributeComponent _attribute, int _offset = 0)
        {
            FP h = Formula.LG(_attribute.Attribute.B_H + _offset) / FP.Sqrt(2);
            return new TSVector(_self.P.x, _self.P.y + h, -h);
        }

        public static TSVector GetCenterPos(this TransformComponent _self, AttributeComponent _attribute, int _offset = 0)
        {
            FP h = Formula.LG((_attribute.Attribute.B_H + _offset) / 2) / FP.Sqrt(2);
            return new TSVector(_self.P.x, _self.P.y + h, -h);
        }

        public static TSVector GetDownPos(this TransformComponent _self)
        {
            return _self.P;
        }
    }
}